package lex.explorer.directory_on_catalog_model;

import javax.swing.tree.DefaultMutableTreeNode;

abstract class LazyMutableTreeNode extends DefaultMutableTreeNode {
	private boolean loaded = false;

	public LazyMutableTreeNode() {
		super();
	}

	public LazyMutableTreeNode(Object userObject) {
		super(userObject);
	}

	public LazyMutableTreeNode(Object userObject, boolean allowsChildren) {
		super(userObject, allowsChildren);
	}

	public int getChildCount() {
		synchronized (this) {
			if (false == loaded) {
				loaded = true;
				loadChildren();
			}
		}
		return super.getChildCount();
	}

	public void clear() {
		removeAllChildren();
		loaded = false;
	}

	public boolean hasLoaded() {
		return loaded;
	}

	protected abstract void loadChildren();
}
